package at.codejedi.sto.gui.combat;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.text.DecimalFormat;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import at.codejedi.sto.config.Configuration;

public class DamagePanel extends JPanel {

	private static final long serialVersionUID = -1940281947240888729L;

	private double allDealt;
	private JTextField allDealtTextField;
	private double allReceived;
	private JTextField allReceivedTextField;

	DecimalFormat df;
	private double perSecondDealt;
	private JTextField perSecondDealtTextField;
	private double perSecondReceived;

	private JTextField perSecondReceivedTextField;

	public DamagePanel(String title) {

		setBorder(BorderFactory.createTitledBorder(title));

		GridBagLayout gbl_netDamagePanel = new GridBagLayout();
		gbl_netDamagePanel.columnWidths = new int[] { 69, 115, 0 };
		gbl_netDamagePanel.rowHeights = new int[] { 28, 0, 0, 0 };
		gbl_netDamagePanel.columnWeights = new double[] { 0.0, 1.0,
				Double.MIN_VALUE };
		gbl_netDamagePanel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0 };
		setLayout(gbl_netDamagePanel);

		JLabel lblPerSecond = new JLabel(
				Configuration.getLabel("Damage.perSecondDealt"));
		GridBagConstraints gbc_lblPerSecond = new GridBagConstraints();
		gbc_lblPerSecond.anchor = GridBagConstraints.EAST;
		gbc_lblPerSecond.insets = new Insets(0, 0, 5, 5);
		gbc_lblPerSecond.gridx = 0;
		gbc_lblPerSecond.gridy = 0;
		add(lblPerSecond, gbc_lblPerSecond);

		perSecondDealtTextField = new JTextField();
		perSecondDealtTextField.setEditable(false);
		GridBagConstraints gbc_netPerSecondDealtTextField = new GridBagConstraints();
		gbc_netPerSecondDealtTextField.insets = new Insets(0, 0, 5, 0);
		gbc_netPerSecondDealtTextField.anchor = GridBagConstraints.NORTH;
		gbc_netPerSecondDealtTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_netPerSecondDealtTextField.gridx = 1;
		gbc_netPerSecondDealtTextField.gridy = 0;
		add(perSecondDealtTextField, gbc_netPerSecondDealtTextField);
		perSecondDealtTextField.setColumns(10);

		JLabel lblNewLabel_1 = new JLabel(
				Configuration.getLabel("Damage.perSecondReceived"));
		GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
		gbc_lblNewLabel_1.anchor = GridBagConstraints.EAST;
		gbc_lblNewLabel_1.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_1.gridx = 0;
		gbc_lblNewLabel_1.gridy = 1;
		add(lblNewLabel_1, gbc_lblNewLabel_1);

		perSecondReceivedTextField = new JTextField();
		perSecondReceivedTextField.setEditable(false);
		GridBagConstraints gbc_netPerSecondReceivedTextField_11 = new GridBagConstraints();
		gbc_netPerSecondReceivedTextField_11.insets = new Insets(0, 0, 5, 0);
		gbc_netPerSecondReceivedTextField_11.fill = GridBagConstraints.HORIZONTAL;
		gbc_netPerSecondReceivedTextField_11.gridx = 1;
		gbc_netPerSecondReceivedTextField_11.gridy = 1;
		add(perSecondReceivedTextField, gbc_netPerSecondReceivedTextField_11);
		perSecondReceivedTextField.setColumns(10);

		JLabel lblDamageDealt = new JLabel(
				Configuration.getLabel("Damage.allDealt"));
		GridBagConstraints gbc_lblDamageDealt = new GridBagConstraints();
		gbc_lblDamageDealt.anchor = GridBagConstraints.EAST;
		gbc_lblDamageDealt.insets = new Insets(0, 0, 5, 5);
		gbc_lblDamageDealt.gridx = 0;
		gbc_lblDamageDealt.gridy = 2;
		add(lblDamageDealt, gbc_lblDamageDealt);

		allDealtTextField = new JTextField();
		allDealtTextField.setEditable(false);
		GridBagConstraints gbc_netAllDealtTextField = new GridBagConstraints();
		gbc_netAllDealtTextField.insets = new Insets(0, 0, 5, 0);
		gbc_netAllDealtTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_netAllDealtTextField.gridx = 1;
		gbc_netAllDealtTextField.gridy = 2;
		add(allDealtTextField, gbc_netAllDealtTextField);
		allDealtTextField.setColumns(10);

		JLabel lblNewLabel = new JLabel(
				Configuration.getLabel("Damage.allReceived"));
		GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
		gbc_lblNewLabel.anchor = GridBagConstraints.EAST;
		gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel.gridx = 0;
		gbc_lblNewLabel.gridy = 3;
		add(lblNewLabel, gbc_lblNewLabel);

		allReceivedTextField = new JTextField();
		allReceivedTextField.setEditable(false);
		GridBagConstraints gbc_netAllReceivedTextField = new GridBagConstraints();
		gbc_netAllReceivedTextField.insets = new Insets(0, 0, 5, 0);
		gbc_netAllReceivedTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_netAllReceivedTextField.gridx = 1;
		gbc_netAllReceivedTextField.gridy = 3;
		add(allReceivedTextField, gbc_netAllReceivedTextField);
		allReceivedTextField.setColumns(10);

		GridBagConstraints gbc_rawDamagePanel = new GridBagConstraints();
		gbc_rawDamagePanel.gridx = 1;
		gbc_rawDamagePanel.gridy = 0;

		setDecimalDisplayFormat();

	}

	public double getAllDealt() {
		return allDealt;
	}

	public double getAllReceived() {
		return allReceived;
	}

	public double getPerSecondDealt() {
		return perSecondDealt;
	}

	public double getPerSecondReceived() {
		return perSecondReceived;
	}

	public void setAllDealt(double allDealt) {

		allDealtTextField.setText(df.format(allDealt));
		this.allDealt = allDealt;
	}

	public void setAllReceived(double allReceived) {
		allReceivedTextField.setText(df.format(allReceived));
		this.allReceived = allReceived;
	}

	private void setDecimalDisplayFormat() {
		df = Configuration.getDecimalFormat();
	}

	public void setPerSecondDealt(double perSecondDealt) {
		perSecondDealtTextField.setText(df.format(perSecondDealt));
		this.perSecondDealt = perSecondDealt;
	}

	public void setPerSecondReceived(double perSecondReceived) {
		perSecondReceivedTextField.setText(df.format(perSecondReceived));
		this.perSecondReceived = perSecondReceived;
	}

}
